package com.firefly.dao.configure;

//import com.mongodb.MongoClientSettings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
import org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * @description: mongodb 连接池
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/10/16
 **/
//@Configuration
public class MongoConfig {
    @Value("${spring.data.mongodb.maxPoolSize}")
    private Integer maxSize;
    @Value("${spring.data.mongodb.minPoolSize}")
    private Integer minSize;
    /*@Bean
    MongoClientSettings mongoClientSettings() {
        MongoClientSettings.Builder builder = MongoClientSettings.builder();
        builder.applyToConnectionPoolSettings(b -> {
            // 允许的最大连接数。这些连接在空闲时将保留在池中。一旦池耗尽，任何需要连接的操作都将阻塞等待可用连接 默认: 100
            b.maxSize(maxSize);
            // 最小连接数。这些连接在空闲时将保留在池中，并且池将确保它至少包含这个最小数量 默认: 0
            b.minSize(minSize);
        });
        return builder.build();
    }*/

    @Bean
    MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties,Environment environment) {
        return new MongoPropertiesClientSettingsBuilderCustomizer(properties, environment);
    }
}
